package com.main;

import com.activities.History;
import com.activities.Log;
import com.activities.MyActivity;
import com.activities.Share;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.content.SharedPreferences;

/**
 * This is the main activity. It extends from TabActivity. Each tab contained in this main activity has one of the services that 
 * the application provides to the user. Each activity is able to come to the front to be accessible by the user, just clicking 
 * the tab that contains it.
 * Two things are made at the very beginning. The first one is the activity that belongs to the application presentation where 
 * the company logo is shown, and the second one is a conditional activity, that will be shown just in case that the application
 * settings have not been set.  
 * */

public class AppTest extends TabActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        presentation();
        checkSettings();
        final TabHost tabHost = getTabHost();

        tabHost.addTab(tabHost.newTabSpec("act1")
                .setIndicator("New Log")
                .setContent(new Intent(this, Log.class)));

        tabHost.addTab(tabHost.newTabSpec("act2")
                .setIndicator("History")
                .setContent(new Intent(this, History.class)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));  // To update the list each time this tab is selected.
        
        tabHost.addTab(tabHost.newTabSpec("act3")
                .setIndicator("Share")
                .setContent(new Intent(this, Share.class)));
    }
    
    /**
     * Launches the application presentation, showing the company logo.
     * */
    private void presentation() {
    	MyActivity.onCreateNewActivity(this, MyActivity.PRESENTATION);
    }
    
    /**
     * Check if the general settings have already been set. If not launches the Setup activity. 
     * */
    private void checkSettings () {
    	//TODO: This method must check the weight units too.
    	SharedPreferences settings = this.getPreferences(0);
        boolean configured = settings.getBoolean("alreadySet", false);
        if (!configured) {
        	MyActivity.onCreateNewActivity(this, MyActivity.SETTINGS);
        }
    }
    
}